/* GUI CONVERTED from rcordmlt.p (converter v1.76) Wed May 15 22:47:44 2002 */
/* rcordmlt.p - Release Management Customer Schedules                         */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                        */
/* All rights reserved worldwide.  This is an unpublished work.               */
/* $Revision: 1.25 $                                                       */
/*V8:ConvertMode=Report                                                       */
/* REVISION: 7.0    LAST MODIFIED: 03/24/92           BY: WUG *F312*          */
/* REVISION: 7.0    LAST MODIFIED: 03/26/92           BY: WUG *F323*          */
/* REVISION: 7.3    LAST MODIFIED: 02/01/93           BY: WUG *G462*          */
/* REVISION: 7.3    LAST MODIFIED: 06/03/93           BY: WUG *GA75*          */
/* REVISION: 7.3    LAST MODIFIED: 02/07/94           BY: WUG *GI61*          */
/* REVISION: 7.3    LAST MODIFIED: 11/03/94           BY: qzl *GO06*          */
/* REVISION: 7.3    LAST MODIFIED: 05/17/95           BY: vrn *G0N0*          */
/* REVISION: 7.3    LAST MODIFIED: 10/18/95           BY: vrn *G0ZW*          */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.0      LAST MODIFIED: 12/02/98   BY: *K1QY* Suresh Nayak       */
/* REVISION: 9.0      LAST MODIFIED: 03/13/99   BY: *M0BD* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 06/04/99   BY: *N00B* Santosh Rao        */
/* REVISION: 9.1      LAST MODIFIED: 08/19/99   BY: *K229* Surekha Joshi      */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 06/06/00   BY: *N0CX* Jean Miller        */
/* REVISION: 9.1      LAST MODIFIED: 07/19/00   BY: *N0GF* Mudit Mehta        */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   BY: *N0KP* Mark Brown         */
/* REVISION: 9.1      LAST MODIFIED: 10/09/00   BY: *N0R9* Jean Miller        */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* Revision: 1.23      BY: Jean Miller          DATE: 03/22/01 ECO: *P008*    */
/* Revision: 1.24      BY: Mercy C.             DATE: 04/25/02 ECO: *N1H5*   */
/* $Revision: 1.25 $    BY: Mercy C.             DATE: 05/13/02 ECO: *N1J6*   */
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/

/* ORDER MULTIPLE CALCULATE/UPDATE CUM QUANTITIES SUBPROGRAM */

/* ********** Begin Translatable Strings Definitions ********* */


/*GUI preprocessor directive settings */
&SCOPED-DEFINE PP_GUI_CONVERT_MODE REPORT

&SCOPED-DEFINE rcordmlt_p_1 "Adjusted!Discrete Qty"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcordmlt_p_2 "Cum Qty"
/* MaxLen: Comment: */

/* MaxLen: Comment: */

&SCOPED-DEFINE rcordmlt_p_4 "Adjusted!Cum Qty"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcordmlt_p_5 "Discrete Qty"
/* MaxLen: Comment: */

&SCOPED-DEFINE rcordmlt_p_6 "Open Qty"
/* MaxLen: Comment: */

/* ********** End Translatable Strings Definitions ********* */

define shared variable global_user_lang_dir like lng_mstr.lng_dir.
define shared variable active_rlse_id       like sch_rlse_id no-undo.

define input parameter sch_recid as recid.
define input parameter ord_mult  like sod_ord_mult.
define input parameter report_yn like mfc_logical.

define variable orig_cum_qty   like schd_cum_qty   column-label {&rcordmlt_p_2}.
define variable new_cum_qty    like schd_cum_qty   column-label {&rcordmlt_p_4}.
define variable orig_discr_qty like schd_discr_qty column-label {&rcordmlt_p_5}.
define variable new_discr_qty  like schd_discr_qty column-label {&rcordmlt_p_1}.

define variable work_diff        as decimal.
define variable cum_qty_ship_rcv as decimal.
define variable first_rec        as logical initial yes.
define variable open_qty         like schd_discr_qty label {&rcordmlt_p_6}.
define variable orig_pcr_qty     like sch_pcr_qty.
define variable active_discr_qty like schd_discr_qty no-undo.
define variable active_firm      like mfc_logical    no-undo.

define shared temp-table t_schd_det no-undo like schd_det.

{gplabel.i} /* EXTERNAL LABEL INCLUDE */

find sch_mstr where recid(sch_mstr) = sch_recid exclusive-lock.

/* DO STANDARD PACK ROUNDING BASED ON NET REQUIRED
 * QUANTITIES, NOT GROSS REQUIRED QUANTITIES*/
if sch_type <= 3 then do:
   find sod_det where sod_nbr = sch_nbr and sod_line = sch_line no-lock.
   cum_qty_ship_rcv = sod_cum_qty[1].
end.
else do:
   find pod_det where pod_nbr = sch_nbr and pod_line = sch_line no-lock.
   cum_qty_ship_rcv = pod_cum_qty[1].
end.

assign
   orig_pcr_qty = sch_pcr_qty
   orig_cum_qty = sch_pcr_qty
   open_qty = max(sch_pcr_qty - cum_qty_ship_rcv,0).

if ord_mult >= 1 and
   sch_type <= 3
then
   sch_pcr_qty = sch_pcr_qty +
                 ((ord_mult - (open_qty modulo ord_mult)) modulo ord_mult).

new_cum_qty = sch_pcr_qty.

for each schd_det exclusive-lock
   where schd_type = sch_type
     and schd_nbr = sch_nbr
     and schd_line = sch_line
     and schd_rlse_id = sch_rlse_id
with frame f-a:

   FORM /*GUI*/ 
      schd_date
      schd_time
      schd_reference
      new_discr_qty
      new_cum_qty
      open_qty
   with STREAM-IO /*GUI*/  frame f-a
   title color normal (getFrameTitle("OPEN_QTY_ADJ_FOR_STD_PACK_QTY",63)) +
                       fill(" ",100)
   width 132.

   setFrameLabels(frame f-a:handle).

   if first_rec     and
      ord_mult >= 1 and
      report_yn
   then do:

      open_qty = max(sch_pcr_qty - cum_qty_ship_rcv,0).

      display
         getTermLabel("PRIOR",8) @ schd_date
         sch_pcr_qty @ new_cum_qty
         open_qty WITH STREAM-IO /*GUI*/ .
   end.

   orig_cum_qty = orig_cum_qty + schd_discr_qty.
   orig_discr_qty = schd_discr_qty.

   active_firm = no.

   if ord_mult      >= 1
      and schd_type > 3
   then do:

      run active_firm_sched
         (input schd_nbr,
          input schd_type,
          input schd_line,
          input schd_date,
          input schd_time,
          output active_firm,
          output active_discr_qty).

      if active_firm = yes
      then
         assign
            orig_cum_qty   = orig_cum_qty - schd_discr_qty +
                             active_discr_qty
            orig_discr_qty = active_discr_qty
            schd_discr_qty = active_discr_qty.

   end. /* IF ord_mult >= 1 AND schd_type > 3 */

   /* NOTE: DONT DO ANYTHING IF IN A SUPLR SCHED AND IT IS FIRM */
   if ord_mult >= 1
      and (schd_type                            <= 3
           or trim(substring(schd_fc_qual,1,1)) <> "f"
           or (can-find(first t_schd_det
                           where t_schd_det.schd_type = schd_det.schd_type
                           and   t_schd_det.schd_nbr  = schd_det.schd_nbr
                           and   t_schd_det.schd_line = schd_det.schd_line
                           and   t_schd_det.schd_rlse_id
                           = schd_det.schd_rlse_id )))

   then do:

      active_firm = no.

      run active_firm_sched
          (input  schd_nbr,
           input  schd_type,
           input  schd_line,
           input  schd_date,
           input  schd_time,
           output active_firm,
           output active_discr_qty ).

      if active_firm = yes
      then
         assign
            orig_cum_qty   = orig_cum_qty - schd_discr_qty +
                             active_discr_qty
            orig_discr_qty = active_discr_qty
            schd_discr_qty = active_discr_qty.

      /* ROUND IT UP */
      open_qty = max(min(schd_discr_qty, orig_cum_qty - cum_qty_ship_rcv),0).

      /* The rounding is done to make the open qty divisible   */
      /* by std pack qty                                       */

      if active_firm = no
      then
         schd_discr_qty = integer(schd_discr_qty) +
         ((ord_mult - (open_qty modulo ord_mult)) modulo ord_mult).

      /* SEE IF NEW CUMULATIVE > OLD CUMULATIVE DUE TO
       * ROUNDING UP AND IF SO REDUCE DISCRETE QTY */
      assign
         work_diff = (new_cum_qty + schd_discr_qty) - orig_cum_qty
         work_diff = truncate(work_diff / ord_mult,0) * ord_mult
         schd_discr_qty = max(schd_discr_qty - work_diff,0)
         new_discr_qty = schd_discr_qty.

   end.

   assign
      new_cum_qty = new_cum_qty + schd_discr_qty
      schd_cum_qty = new_cum_qty.

   if ord_mult >= 1 and report_yn
      and (schd_type                            <= 3
           or trim(substring(schd_fc_qual,1,1)) <> "f"
           or (can-find(first t_schd_det
                        where t_schd_det.schd_type = schd_det.schd_type
                        and   t_schd_det.schd_nbr  = schd_det.schd_nbr
                        and   t_schd_det.schd_line = schd_det.schd_line
                        and   t_schd_det.schd_rlse_id
                        = schd_det.schd_rlse_id )))
   then do:

      active_firm = no.

      run active_firm_sched
         (input  schd_nbr,
          input  schd_type,
          input  schd_line,
          input  schd_date,
          input  schd_time,
          output active_firm,
          output active_discr_qty ).

      if active_firm = yes
      then
         assign
            new_cum_qty    = new_cum_qty - schd_discr_qty +
                             active_discr_qty
            schd_cum_qty   = new_cum_qty
            schd_discr_qty = active_discr_qty.

      if first_rec then down 1.
      open_qty = max(min(schd_discr_qty, new_cum_qty - cum_qty_ship_rcv),0).

      display
         schd_date
         schd_time
         schd_reference
         schd_discr_qty    @ new_discr_qty
         schd_cum_qty      @ new_cum_qty
         open_qty WITH STREAM-IO /*GUI*/ .
   end.

   if ord_mult >= 1      and
      schd_discr_qty = 0 and
      schd_type <> 6
   then
      delete schd_det.

   first_rec = no.

end.

/* DELETE THE TEMP TABLE USED FOR FIRM REQUIREMENTS */
for each t_schd_det
   exclusive-lock:
   delete t_schd_det.
end. /* FOR EACH t_schd_det */

/* TO FIND ACTIVE FIRM SCHEDULE AND ITS DISCRETE QUANTITY */
PROCEDURE active_firm_sched:

   define input parameter act_pod_nbr like pod_nbr            no-undo.
   define input parameter act_type    like schd_det.schd_type no-undo.
   define input parameter act_line    like schd_det.schd_line no-undo.
   define input parameter act_date    like schd_det.schd_date no-undo.
   define input parameter act_time    like schd_det.schd_time no-undo.

   define output parameter act_firm      like mfc_logical             no-undo.
   define output parameter act_discr_qty like schd_det.schd_discr_qty no-undo.

   define buffer act_firm_schd for schd_det.

   assign
      act_firm      = No
      act_discr_qty = 0.

   for each act_firm_schd
      fields (schd_cum_qty schd_date schd_discr_qty schd_fc_qual
              schd_line    schd_nbr  schd_reference schd_rlse_id
              schd_time    schd_type )
      where act_firm_schd.schd_nbr     = act_pod_nbr
      and   act_firm_schd.schd_rlse_id = active_rlse_id
      and   act_firm_schd.schd_type    = act_type
      and   act_firm_schd.schd_line    = act_line
      and   act_firm_schd.schd_date    = act_date
      and   act_firm_schd.schd_time    = act_time
      and   trim(substring(act_firm_schd.schd_fc_qual,1,1)) = "F"
      no-lock:

      assign
         act_firm      = yes
         act_discr_qty = act_firm_schd.schd_discr_qty.
   end. /* FOR EACH act_firm_schd */

END PROCEDURE. /* PROCEDURE active_firm_sched */
